package cn.zzp.xhr;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @ClassName Producer
 * @Description
 * @Author 祝志鹏
 * @Date 2022/8/16 17:58
 */
public class Producer {

    public static void main(String[] args) throws Exception {

        DefaultMQProducer producer = new DefaultMQProducer("xhr_product_group");

        producer.setNamesrvAddr("localhost:9876");

        producer.start();
        Message message = new Message("xhr", "hello", "我爱你我的家，我的家我的天堂".getBytes(StandardCharsets.UTF_8));

        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("消息发布成功");
            }

            @Override
            public void onException(Throwable throwable) {

            }
        });


    }
}
